<script setup>
import { Plus } from "@element-plus/icons-vue";
import useTable from "@/utils/useTable";
import {http} from "@/api";

// 展示区域列表  1首页,2产业政策,3电瓷产品
const regionList = [
  {
    name: '首页',
    id: '1'
  },
  {
    name: '产业政策',
    id: '2'
  },
  {
    name: '电瓷产品',
    id: '3'
  },
  {
    name: '电瓷产品',
    id: '3'
  },
  {
    name: '驾驶舱',
    id: '4'
  }
]
/**
 * 表格
 * @type {Ref<UnwrapRef<*[]>>}
 */
const {
  searchParams,
  pageNo,
  pageSize,
  total,
  changePage,
  changeSize,
  dataSource,
  search,
  reset,
  openAdd,
  openView,
  openEdit,
  openDelete
} = useTable({
  requestFn: http.banner,
  routerPre: 'banner',
  params: {
    region: '',
  }
})
</script>


<template>
  <PageMain title="轮播管理">
    <el-form label-suffix="：" inline>
      <el-form-item label="展示区域">
        <el-select v-model="searchParams.region" placeholder="请选择">
          <el-option v-for="item in regionList" :label="item.name" :value="item.id" :key="item.id"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="add-box">
      <el-button type="primary" :icon="Plus" @click="openAdd">添加</el-button>
    </div>
    <div class="table-box">
      <el-table :data="dataSource">
        <el-table-column label="图片">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <ViewImage type="image" :image-url="scope.row.imageUrl"/>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="展示状态">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <el-switch :active-value="0" :inactive-value="1" v-model="scope.row.status"/>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="展示区域" prop="region">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <span>{{ regionList.find(e => e.id == scope.row.region)?.name || scope.row.region}}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="跳转链接">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <el-link :href="scope.row.link" target="_blank">
                {{ scope.row.link }}
              </el-link>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="展示开始时间" prop="startTime"></el-table-column>
        <el-table-column label="展示结束时间" prop="endTime"></el-table-column>
        <el-table-column label="操作" fixed="right" width="200px">
          <template #default="scope">
            <el-button type="text" @click="openEdit(scope.row)">编辑</el-button>
            <el-button type="text" @click="openDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
          v-model:current-page="pageNo"
          v-model:page-size="pageSize"
          :page-sizes="[10, 50, 100, 200]"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="changeSize"
          @current-change="changePage"
      />

    </div>
  </PageMain>
</template>

<style scoped lang="scss">

</style>
